<?php


namespace app\admin\middleware;


use app\common\traits\JumpTrait;
use think\exception\ValidateException;
use think\Response;

/**
 * 表单令牌验证
 * Class TokenCheck
 * @package app\admin\middleware
 */
class TokenCheck
{
    use JumpTrait;

    public function handle($request, \Closure $next)
    {
        if (config('app.csrf_token') && $request->isAjax()) {
            $check = $request->checkToken('__token__');
            if (false === $check) {
                $this->error('表单令牌验证失败，刷新页面后重试');
            }
        }
        return $next($request);
    }

}